package com.android.mios.adapter;

import com.android.mios.R;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class SensorShortcutKeyListViewAdapter extends CursorAdapter {
	private LayoutInflater mInflater;

	public SensorShortcutKeyListViewAdapter(Context context, Cursor c,
			boolean autoRequery) {
		super(context, c, autoRequery);
		mInflater = LayoutInflater.from(context);

	}

	static class ViewHolder {
		TextView tvName;
		TextView tvId;
		TextView tvFlag;
		CheckBox cbSelect;
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		final View view = mInflater.inflate(
				R.layout.lv_sensor_shortcutkey_item, null);
		ViewHolder holder = new ViewHolder();
		holder.tvName = (TextView) view
				.findViewById(R.id.tv_sensor_shortcutkey_item);
		holder.tvId = (TextView) view
				.findViewById(R.id.tv_sensor_shortcutkey_id);
		holder.tvFlag = (TextView) view
				.findViewById(R.id.tv_sensor_shortcutkey_flag);
		holder.cbSelect = (CheckBox) view
				.findViewById(R.id.cb_sensor_shortcutkey_item);
		view.setTag(holder);
		return view;
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		final ViewHolder holder = (ViewHolder) view.getTag();
		String name = cursor.getString(cursor.getColumnIndex("CName"));
		int isSelect = cursor.getInt(cursor.getColumnIndex("CIscheck"));
		int id = cursor.getInt(cursor.getColumnIndex("CID"));
		int flag = cursor.getInt(cursor.getColumnIndex("CFlag"));
		holder.tvFlag.setText(String.valueOf(flag));
		holder.tvName.setText(name);
		holder.tvId.setText(String.valueOf(id));
		if (isSelect == 0)
			holder.cbSelect.setChecked(false);
		else
			holder.cbSelect.setChecked(true);
	}
}